package com.szp.drug.component.controller;

import com.github.pagehelper.PageInfo;
import com.szp.drug.entity.DrugSell;
import com.szp.drug.entity.DrugSellPage;
import com.szp.drug.util.ResultEntity;
import com.szp.drug.component.service.api.DrugSellService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 售出记录前端控制器
 * @author SuZePing
 * @create 2021-03-06 13:58
 * @E-mail suzeping10@126.com
 */
@Slf4j
@RestController
@RequestMapping("/sell")
public class DrugSellController {

	@Autowired
	private DrugSellService sellService;

	/**
	 * 获取全部在售药品及器械
	 * @return
	 */
	@GetMapping("/getAllOther.json")
	public ResultEntity<List<Map<String,Object>>> getAllOther(){
		return sellService.getAllOther();
	}

	/**
	 * 获取药品或器械的单价
	 * @return
	 */
	@PostMapping("/getOtherPrice.json")
	public ResultEntity<String> getOtherPrice(String otherId){
		return sellService.getOtherPrice(otherId);
	}

	/**
	 * 分页获取售出记录
	 * @param sellName
	 * @param otherName
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/get/page.json")
	public ResultEntity<PageInfo<DrugSellPage>> getPageInfo(
			@RequestParam(value = "sellName",defaultValue = "") String sellName,
			@RequestParam(value = "otherName",defaultValue = "") String otherName,
			@RequestParam(value = "pageNum",defaultValue = "1") String pageNum,
			@RequestParam(value = "pageSize",defaultValue = "5") String pageSize
	){
		return sellService.getPageInfo(sellName, otherName, pageNum, pageSize);
	}

	/**
	 * 售出记录(返回新增后记录总数量、药品或器械剩余数量及产品名称)
	 * @param sell
	 * @return
	 */
	@PostMapping("/save.json")
	public ResultEntity<Map<String,Object>> saveSell(DrugSell sell){
		return sellService.saveSell(sell);
	}

	/**
	 * 删除记录
	 * @param sellId
	 * @return
	 */
	@PostMapping("/del.json")
	public ResultEntity<String> removeSell(@RequestParam("sellId") String sellId){
		return sellService.removeSell(sellId);
	}
}